//package com.top.art.utils;
//
//
//import org.springframework.stereotype.Component;
//
//
//import java.awt.Image;
//import java.awt.image.BufferedImage;
//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import javax.imageio.ImageIO;
//
//import org.apache.commons.io.FileUtils;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.google.zxing.BarcodeFormat;
//import com.google.zxing.EncodeHintType;
//import com.google.zxing.MultiFormatWriter;
//import com.google.zxing.WriterException;
//import com.google.zxing.common.BitMatrix;
//import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
//import com.itextpdf.text.BaseColor;
//import com.itextpdf.text.Document;
//import com.itextpdf.text.DocumentException;
//import com.itextpdf.text.Font;
//import com.itextpdf.text.FontFactory;
//import com.itextpdf.text.Paragraph;
//import com.itextpdf.text.Phrase;
//import com.itextpdf.text.pdf.BaseFont;
//import com.itextpdf.text.pdf.PdfPCell;
//import com.itextpdf.text.pdf.PdfPTable;
//import com.itextpdf.text.pdf.PdfWriter;
//import com.msjsol.exam.common.IString;
//import com.msjsol.exam.common.Security;
//import com.msjsol.exam.common.barcode.MatrixToImageWriter;
//import com.msjsol.exam.model.vo.RoomStudentVO;
//
//import sun.misc.BASE64Decoder;
//import sun.misc.BASE64Encoder;
//
///**
// * @author zhubg
// * @title: QRCodeUtils
// * @projectName art-exam-manager
// * @description: TODO
// * @date 2020/10/13-20:59
// */
//@Component
//public class QRCodeUtils {
//
//    public void creatPdf_GuanSu() throws Exception {
//        List<String> names = FileUtils.readLines(new File("d:\\code\\name.txt"));
//        List<String> idcards = FileUtils.readLines(new File("d:\\code\\idcard.txt"));
//        List<RoomStudentVO> list = new ArrayList<>();
//        for (int i = 0; i < 100; i++) {
//            RoomStudentVO vo = new RoomStudentVO();
//            // 生成18位随机数字
//            vo.setIdCord(idcards.get(i));
//            vo.setRoomCode("168");
//            vo.setStudentId(331);
//            vo.setStudentName(names.get(i));
//            vo.setSubjectId(2);
//            vo.setSubjectName("速写");
//            vo.setTicket("2" + String.format("%07d", (i + 1)));
//            list.add(vo);
//        }
//        PdfTest t = new PdfTest();
//        p(t.printToPDF(list));
//    }
//
//    static void imgTest() {
//        String str = "/9j/4AAQSkZJRgABAgIAAAAAAAD//gAeQUNEIFN5c3RlbXMgRGlnaXRhbCBJbWFnaW5nAP/AABEIANkAvAMBIgACEQEDEQH/2wCEAAcEBQYFBAcGBQYHBwcIChELCgkJChUPEAwRGRYaGhgWGBgcHygiHB0mHhgYIy8jJikqLS0tGyExNDErNCgsLSsBCwsLDw0PHhERHkArJCtAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQP/EAJAAAAEFAQEAAAAAAAAAAAAAAAEAAgMEBQYHEAABAwMDAgUBBAgGAQUAAAABAAIDBBEhBRIxQVEGEyJhcYEyM5HBFCM0QqGx0fBSYnJz4fEHFSQ1Q4IBAAIDAQAAAAAAAAAAAAAAAAABAgMEBREAAgMAAgICAgIDAAAAAAAAAAECAxESIQQxIkETMkJRM2GB/9oADAMBAAIRAxEAPwDkco/xQP4/VHHTlazmi+UQPZCwOEQBbj4QIWL2CDsAJ3PsmoGCxvj+KVij2Isl0QACj3v3THPDeSs+p1eCIlrXEuHRJtIai36NAnCG/OCFzlX4iLQdjRf3WbP4iqXDG0C+AAofkRaqZHaskaWn2SORc4XDwa7MZPWbrfg1iIQgudfHHVNTQpVNG0XY5SBF+qx261EXDeCG9CtOkqY5o9zH3HspKSZBxaJhyEgkCOh5RFuFIiL5P4o4vfCXIyUj2sgQjx1QHGD+KVxblA4QAPxThwhcX55QugY7nhG3GUB8pwsoiF06I9v4oH3wke6ACRlNN+904IE5KYDRYC5VPU9RioId8rhuOWtPJS1fUI9PpzI/JOA29rrkpp5K+q8ydxd2HQDsq5Twurr5dssVm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9UnaY3WY1oFx9fzUVXVUx0yoOw3LgLBl75A6fKnpKqIz1LzEQd3JHYW/JQVU0MmmhrYyN0g6Dvf8AJIY6QxbKeOLb6GDcbWyizLumPdMfI2SZ7mt2gYHp7JzLBrnYXE8mXKxnQqWRDcEuTQNsjW9gjCNzflC22Rzzm2FQWEUgcI2gYOT+KFQ7yaX3Usw9fthQ1bPMljZyL3ITQfYqaGzd7zclTE5SeQxoAxZRAufcgHlJDZT1Bt4A4dFUp6wQyBryRfCv1P7G5Y9d90EJhhq1oElK4DnopNOkD6dpHUKKH9malo37OEvpgy1Oz1F3VoUEpDqraeALqxUf/Z/t/kqY/anf7aaEy7ELR+yDmCQbHXAOMIs+4CY/7P8A+lOn/IhT/Vkb3U8NQwF17xkAc5CldWNNHFsjdYScfQrMd+1Q/Lv5rbj/APj2/wCpd85hWrJJnMn8uIW8vqnSw1D4YQdoBbn8FPWfd1H+1/VSt+4h/wBP5KO9jwpaXUTx0VPC5rZLSm3xYrWlqnNrIw+JwuDws/Tvs03+s/yK1qr9rj+EJg0UqWsjEVQdj8Pf/MqCSvbupoyx2wXcflX6T7if5f8AzKy679pb/t/1TecWJaPYbsLjcXyi4jyMm902D7pvwE6b7oLgSes6a9ElPhoCbNfynFtufzTo+GpS/du+VBkkRvILyD3UIINS4/4QpZfvj8qtD+0yfRP6AdITLLsCsl7IgG9gq1D+0PSqPvnfKT7Yz//Z";
//
//        String imgStr = getImageBinary();
//        JSONObject obj = new JSONObject();
//        obj.put("photo", imgStr);
//        String json = obj.toJSONString();
//        p(json);
//
//        base64StringToImage(str);
//
//    }
//
//    /**
//     * 将图片转换成二进制
//     *
//     * @return
//     */
//    static String getImageBinary() {
//        String src = "D:\\docs\\准考证\\ad.png";
//        File f = new File(src);
//        BufferedImage bi;
//        try {
//            bi = ImageIO.read(f);
//            ByteArrayOutputStream baos = new ByteArrayOutputStream();
//            ImageIO.write(bi, "jpg", baos); // 经测试转换的图片是格式这里就什么格式，否则会失真
//            byte[] bytes = baos.toByteArray();
//            BASE64Encoder encoder = new sun.misc.BASE64Encoder();
//            return encoder.encodeBuffer(bytes).trim();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    /**
//     * 将二进制转换为图片
//     *
//     * @param base64String
//     */
//    static void base64StringToImage(String base64String) {
//        try {
//            BASE64Decoder decoder = new sun.misc.BASE64Decoder();
//            byte[] bytes1 = decoder.decodeBuffer(base64String);
//            ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);
//            BufferedImage bi1 = ImageIO.read(bais);
//            // 可以是jpg,png,gif格式
//            File w2 = new File("e://QQ.jpg");
//            // 不管输出什么格式图片，此处不需改动
//            ImageIO.write(bi1, "jpg", w2);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void p(String msg) {
//        System.out.println(msg);
//    }
//
//    public static void p(Object o) {
//        System.out.println(JSON.toJSONString(o));
//    }
//
//    public static void creatOnePdfTest() throws Exception {
//        RoomStudentVO vo = new RoomStudentVO();
//        // 生成18位随机数字
//        vo.setIdCord(Security.getRandomNumbers(18));
//        vo.setRoomCode("001");
//        vo.setStudentId(269);
//        vo.setStudentName("许照龙儿");
//        vo.setSubjectId(1);
//        vo.setSubjectName("素描");
//        String code = String.valueOf(vo.getSubjectId()) + String.format("%07d", vo.getStudentId());
//        vo.setTicket(code);
//        PdfTest t = new PdfTest();
//        p(t.printOneToPDF(vo));
//    }
//
//    public static void creatListPdfTest() throws Exception {
//        String[] tmp = "10010030,10010031,10010032,10010033,10010034,10010035,10010036,10010037,10010038,10010039,10010040,10020001,10020002,10020003,10020004,10020005,10020006,10020007,10020008,10020009,10020010"
//                .split(",");
//        tmp = "10010001,10010002,10010003,10010004,10010005,10010006,10010007,10010008,10010009,10010010,10020011,10020012,10020013,10020014,10020015,10020016,10020017,10020018,10020019,10020020"
//                .split(",");
//        List<RoomStudentVO> list = new ArrayList<>();
//        int n = 1;
//        for (String code : tmp) {
//            RoomStudentVO vo = new RoomStudentVO();
//            // 生成18位随机数字
//            vo.setIdCord(Security.getRandomNumbers(18));
//            vo.setRoomCode("103");
//            vo.setStudentId(331);
//            vo.setStudentName("考生姓名" + n);
//            vo.setSubjectId(2);
//            vo.setSubjectName("速写");
//            vo.setTicket(code);
//            list.add(vo);
//            n++;
//        }
//
//        PdfTest t = new PdfTest();
//        p(t.printToPDFLeft(list));
//        // p(t.printToPDF(list));
//
//    }
//
//    /** 毫米 转 像素 */
//    static final double mm2px = 3.779527559;
//    /** 毫米 转 点位数pt */
//    static final double mm2pt = 2.834947225;
//
//    // PDF中的测量单位是points,传统的图形行业测量单位. Adobe使用以下定义：
//    // 1 pt = 1/72 inch
//    // 并且由于将一英寸定义为正好为25.4毫米,可以使用公式将点数转换为mm
//    // mm = pt*25.4 / 72
//
//    // 100 * 3.779527559 或着 100 / 0.264583333
//    // 打印纸宽度高度（毫米）
//    int paperWidth_mm = 50;
//    int paperHeight_mm = 40;
//    // 二维码宽度高度（毫米）
//    int barcodeWidth_mm = 18;
//    // 打印纸宽度 40mm
//    int paperWidth = (int) (paperWidth_mm * mm2px);
//    // 打印纸高度 30mm
//    int paperHeight = (int) (paperHeight_mm * mm2px);
//
//    public String printOneToPDF(RoomStudentVO vo) throws WriterException, IOException, DocumentException {
//        String pdfName = "d:\\barcode\\qrcode\\" + vo.getTicket() + ".pdf";
//        // PDF的大小需要重新计算
//        int w = (int) (paperWidth_mm * mm2pt);
//        int h = (int) (paperHeight_mm * mm2pt);
//
//        // 二维码内容（科目编码1位+7位学生ID）
//        String code = vo.getTicket();
//        // 生成二维码 图像宽度转成px
//        int barcodeWidthPx = (int) (this.barcodeWidth_mm * mm2px);
//        BufferedImage codeImg = getBarcodeImg(code, barcodeWidthPx);
//        String codeFileName = "d:\\barcode\\qrcode\\qrsrc" + code + ".jpg";
//        File fileCode = new File(codeFileName);
//        ImageIO.write(codeImg, "JPEG", fileCode);
//
//        com.itextpdf.text.Rectangle rectangle = new com.itextpdf.text.Rectangle(w, h);
//        rectangle.rotate();
//        Document docpdf = new Document(rectangle, 1, 0, 1, 0);
//        // docpdf.setMargins(0, 0, 0, 0);
//        PdfWriter pdfWriter = PdfWriter.getInstance(docpdf, new FileOutputStream(pdfName));
//        docpdf.open();
//        PdfPTable table = new PdfPTable(3);
//        // 表格宽度100%
//        table.setWidthPercentage(100);
//        table.getDefaultCell().setBorder(0);
//        // 设置表格列宽（相对）
//        // float[] widths = { 0.7f, 0.3f };
//        // 设置表格列宽（绝对）
//        float[] widths2 = { 80f, 51f, 10f };
//        table.setWidths(widths2);
//        PdfPCell cell;
//
//        Font ft14 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 14f, Font.BOLD,
//                BaseColor.BLACK);
//        Font ft12 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 12f, Font.BOLD,
//                BaseColor.BLACK);
//        Font ft8 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 8f, Font.BOLD,
//                BaseColor.BLACK);
//        Font ft9 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 9f, Font.BOLD,
//                BaseColor.BLACK);
//
//        String kemu = "科  目：" + vo.getSubjectName();
//        String kaoChang = "考  场：" + vo.getRoomCode();
//        String ticket = "准考证：" + vo.getTicket();
//        String idcard = "身份证：" + vo.getIdCord();
//        cell = new PdfPCell(new Paragraph());
//        cell.setBorder(0);
//        cell.setPadding(0f);
//
//        // String strText = String.format("%s\r\n%s\r\n%s", vo.getStudentName(), kemu,
//        // kaoChang);
//        Paragraph paragraph = new Paragraph(vo.getStudentName(), ft9);
//        paragraph.setSpacingBefore(0f);
//        paragraph.setSpacingAfter(0f);
//        paragraph.setPaddingTop(0f);
//        cell.addElement(paragraph);
//
//        paragraph = new Paragraph(kemu, ft9);
//        paragraph.setSpacingBefore(2f);
//        paragraph.setSpacingAfter(0f);
//        paragraph.setPaddingTop(0f);
//        cell.addElement(paragraph);
//
//        paragraph = new Paragraph(kaoChang, ft9);
//        paragraph.setSpacingBefore(2f);
//        paragraph.setSpacingAfter(0f);
//        paragraph.setPaddingTop(0f);
//        cell.addElement(paragraph);
//        table.addCell(cell);
//
//        // cell = new PdfPCell(new Phrase("第一行，第二列",ft14));
//        // 图片添加到PDF格子中
//        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(codeFileName);
//        image.setBorder(0);
//        // cell = new PdfPCell(image);
//        // cell.setBorder(0);
//        // cell.setVerticalAlignment(Element.ALIGN_TOP);
//        // cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//
//        table.addCell(image);
//        // 空白列
//        cell = new PdfPCell(new Phrase(" ", ft9));
//        cell.setBorder(0);
//        table.addCell(cell);
//        // cell = new PdfPCell(new Phrase(ticket + "\r\n" + idcard, ft9));
//        cell = new PdfPCell(new Paragraph());
//        cell.setColspan(3);
//
//        paragraph = new Paragraph(ticket, ft9);
//        paragraph.setSpacingBefore(0f);
//        paragraph.setSpacingAfter(0f);
//        paragraph.setPaddingTop(0f);
//        cell.addElement(paragraph);
//
//        paragraph = new Paragraph(idcard, ft9);
//        paragraph.setSpacingBefore(0f);
//        paragraph.setSpacingAfter(0f);
//        paragraph.setPaddingTop(0f);
//        cell.addElement(paragraph);
//
//        cell.setPadding(0f);
//        cell.setBorder(0);
//        table.addCell(cell);
//        docpdf.add(table);
//        docpdf.close();
//        pdfWriter.close();
//        fileCode.delete();
//        return pdfName;
//    }
//
//    /**
//     * 生成准考证二维码（码在右上角）
//     *
//     * @param list
//     * @return
//     * @throws WriterException
//     * @throws IOException
//     * @throws DocumentException
//     */
//    public String printToPDF(List<RoomStudentVO> list) throws WriterException, IOException, DocumentException {
//        String pdfName = "d:\\barcode\\qrcode\\" + list.get(0).getRoomCode() + ".pdf";
//        // PDF的大小需要重新计算
//        int w = (int) (paperWidth_mm * mm2pt);
//        int h = (int) (paperHeight_mm * mm2pt);
//
//        com.itextpdf.text.Rectangle rectangle = new com.itextpdf.text.Rectangle(w, h);
//        Document docpdf = new Document(rectangle, 0, 0, 0, 0);
//        PdfWriter pdfWriter = PdfWriter.getInstance(docpdf, new FileOutputStream(pdfName));
//        docpdf.open();
//        // 打印考场人数信息，方便操作人员区分考场
//        printRoomInfo(docpdf, list.get(0).getRoomCode(), list.size());
//        // 循环打印每个学生的准考证标签
//        for (RoomStudentVO vo : list) {
//            docpdf.newPage();
//            // 二维码内容（科目编码1位+7位学生ID）
//            String code = vo.getTicket();
//            // 生成二维码 图像宽度转成px
//            int barcodeWidthPx = (int) (this.barcodeWidth_mm * mm2px);
//            BufferedImage codeImg = getBarcodeImg(code, barcodeWidthPx);
//            String codeFileName = "d:\\barcode\\qrcode\\qrsrc" + code + ".jpg";
//            File fileCode = new File(codeFileName);
//            if (!fileCode.exists()) {
//                fileCode.mkdirs();
//            }
//            ImageIO.write(codeImg, "JPEG", fileCode);
//
//            PdfPTable table = new PdfPTable(3);
//            // 表格宽度100%
//            table.setWidthPercentage(100);
//            table.getDefaultCell().setBorder(0);
//            // 设置表格列宽（相对）
//            // float[] widths = { 0.7f, 0.3f };
//            // 设置表格列宽（绝对）
//            float[] widths2 = { 80f, 51f, 10f };
//            table.setWidths(widths2);
//            PdfPCell cell;
//
//            Font ft14 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 14f, Font.BOLD,
//                    BaseColor.BLACK);
//            Font ft12 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 12f, Font.BOLD,
//                    BaseColor.BLACK);
//            Font ft9 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 9f, Font.BOLD,
//                    BaseColor.BLACK);
//
//            String kemu = "科  目：" + vo.getSubjectName();
//            String kaoChang = "考  场：" + vo.getRoomCode();
//            String ticket = "准考证：" + vo.getTicket();
//            String idcard = "身份证：" + vo.getIdCord();
//            cell = new PdfPCell(new Paragraph());
//            cell.setBorder(0);
//            cell.setPadding(0f);
//
//            // String strText = String.format("%s\r\n%s\r\n%s", vo.getStudentName(), kemu,
//            // kaoChang);
//            Paragraph paragraph = new Paragraph(vo.getStudentName(), ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(kemu, ft9);
//            paragraph.setSpacingBefore(2f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(kaoChang, ft9);
//            paragraph.setSpacingBefore(2f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//            table.addCell(cell);
//
//            // cell = new PdfPCell(new Phrase("第一行，第二列",ft14));
//            // 图片添加到PDF格子中
//            com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(codeFileName);
//            image.setBorder(0);
//            // cell = new PdfPCell(image);
//            // cell.setBorder(0);
//            // cell.setVerticalAlignment(Element.ALIGN_TOP);
//            // cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//
//            table.addCell(image);
//            // 空白列
//            cell = new PdfPCell(new Phrase(" ", ft9));
//            cell.setBorder(0);
//            table.addCell(cell);
//            // cell = new PdfPCell(new Phrase(ticket + "\r\n" + idcard, ft9));
//            cell = new PdfPCell(new Paragraph());
//            cell.setColspan(3);
//
//            paragraph = new Paragraph(ticket, ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(idcard, ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            cell.setPadding(0f);
//            cell.setBorder(0);
//            table.addCell(cell);
//            docpdf.add(table);
//
//            fileCode.delete();
//        }
//        docpdf.close();
//        pdfWriter.close();
//        return pdfName;
//    }
//
//    /**
//     * 打印考场号+学生数量
//     *
//     * @param docpdf
//     * @param roomCode
//     * @param stuCount
//     * @throws DocumentException
//     */
//    private void printRoomInfo(Document docpdf, String roomCode, int stuCount) throws DocumentException {
//        docpdf.newPage();
//        Font ft14 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 14f, Font.BOLD,
//                BaseColor.BLACK);
//        Font ft8 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 8f, Font.BOLD,
//                BaseColor.BLACK);
//        Paragraph paragraph = new Paragraph(" ", ft8);
//        paragraph.setSpacingBefore(0f);
//        paragraph.setSpacingAfter(0f);
//        docpdf.add(paragraph);
//        paragraph = new Paragraph(" 考场：" + roomCode, ft14);
//        paragraph.setSpacingBefore(0f);
//        paragraph.setSpacingAfter(0f);
//        docpdf.add(paragraph);
//        paragraph = new Paragraph(" 考生：" + stuCount + " 人", ft14);
//        paragraph.setSpacingBefore(5f);
//        paragraph.setSpacingAfter(0f);
//        docpdf.add(paragraph);
//
//    }
//
//    /**
//     * 生成二维码图片
//     *
//     * @param code
//     * @param width_mm
//     * @return
//     * @throws WriterException
//     * @throws IOException
//     */
//    BufferedImage getBarcodeImg(String code, int width_px) throws WriterException, IOException {
//        int width = width_px;
//        // 图像高度 = 宽度
//        int height = width;
//        Map<EncodeHintType, Object> hints = new HashMap<>();
//        // 内容编码格式
//        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
//        // 指定纠错等级
//        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//        // 设置二维码边的空度，非负数
//        hints.put(EncodeHintType.MARGIN, 0);
//        BitMatrix bitMatrix = new MultiFormatWriter().encode(code, BarcodeFormat.QR_CODE, width, height, hints);
//        // 输出原图片
//        BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
//        // ImageIO.write(image, "JPEG", new File("d:\\barcode\\qrcode\\qrsrc-" + code +
//        // ".jpg"));
//        return image;
//    }
//
//    /**
//     * 生成准考证二维码（码在左下角）
//     * @param list
//     * @return
//     * @throws WriterException
//     * @throws IOException
//     * @throws DocumentException
//     */
//    public String printToPDFLeft(List<RoomStudentVO> list) throws WriterException, IOException, DocumentException {
//        String pdfName = "d:\\barcode\\qrcode\\" + list.get(0).getRoomCode() + ".pdf";
//        // PDF的大小需要重新计算
//        int w = (int) (paperWidth_mm * mm2pt);
//        int h = (int) (paperHeight_mm * mm2pt);
//
//        com.itextpdf.text.Rectangle rectangle = new com.itextpdf.text.Rectangle(w, h);
//        Document docpdf = new Document(rectangle, 0, 0, 0, 0);
//        PdfWriter pdfWriter = PdfWriter.getInstance(docpdf, new FileOutputStream(pdfName));
//        docpdf.open();
//        // 打印考场人数信息，方便操作人员区分考场
//        printRoomInfo(docpdf, list.get(0).getRoomCode(), list.size());
//        // 循环打印每个学生的准考证标签
//        for (RoomStudentVO vo : list) {
//            docpdf.newPage();
//            // 二维码内容（科目编码1位+7位学生ID）
//            String code = vo.getTicket();
//            // 生成二维码 图像宽度转成px
//            int barcodeWidthPx = (int) (this.barcodeWidth_mm * mm2px);
//            BufferedImage codeImg = getBarcodeImg(code, barcodeWidthPx);
//            String codeFileName = "d:\\barcode\\qrcode\\qrsrc" + code + ".jpg";
//            File fileCode = new File(codeFileName);
//            if (!fileCode.exists()) {
//                fileCode.mkdirs();
//            }
//            ImageIO.write(codeImg, "JPEG", fileCode);
//
//            PdfPTable table = new PdfPTable(3);
//            // 表格宽度100%
//            table.setWidthPercentage(100);
//            int border = 0;
//            table.getDefaultCell().setBorder(border);
//            // 设置表格列宽（相对）
//            // float[] widths = { 0.7f, 0.3f };
//            // 设置表格列宽（绝对）
//            float[] widths2 = {63f, 3f, 78f };
//            table.setWidths(widths2);
//            PdfPCell cell;
//            Paragraph paragraph;
//
//            //Font ft14 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 14f, Font.BOLD, BaseColor.BLACK);
//            // Font ft12 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 12f, Font.BOLD, BaseColor.BLACK);
//            Font ft9 = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, 9f, Font.BOLD,
//                    BaseColor.BLACK);
//
//            String kemu = "科  目：" + vo.getSubjectName();
//            String kaoChang = "考  场：" + vo.getRoomCode();
//            String ticket = "准考证：" + vo.getTicket();
//            String idcard = "身份证：" + vo.getIdCord();
//
//            cell = new PdfPCell(new Paragraph());
//            cell.setColspan(3);
//
//            paragraph = new Paragraph(ticket, ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(idcard, ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            cell.setPadding(0f);
//            cell.setBorder(border);
//            cell.setPaddingBottom(10f);
//            table.addCell(cell);
//
//            cell = new PdfPCell(new Paragraph());
//            cell.setBorder(border);
//            cell.setPadding(0f);
//            // cell = new PdfPCell(new Phrase("第一行，第二列",ft14));
//            // 图片添加到PDF格子中
//            com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(codeFileName);
//            image.setBorder(border);
//            //image.setAbsolutePosition(0f, 0f);
//            //image.setWidthPercentage(20f);
//            // cell = new PdfPCell(image);
//            // cell.setBorder(0);
//            // cell.setVerticalAlignment(Element.ALIGN_TOP);
//            // cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            table.addCell(image);
//
//            // 空白列
//            cell = new PdfPCell(new Phrase(" ", ft9));
//            cell.setBorder(border);
//            table.addCell(cell);
//
//            //姓名、科目、考场
//
//            paragraph = new Paragraph(vo.getStudentName(), ft9);
//            paragraph.setSpacingBefore(0f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(kemu, ft9);
//            paragraph.setSpacingBefore(2f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//
//            paragraph = new Paragraph(kaoChang, ft9);
//            paragraph.setSpacingBefore(2f);
//            paragraph.setSpacingAfter(0f);
//            paragraph.setPaddingTop(0f);
//            cell.addElement(paragraph);
//            table.addCell(cell);
//
//            docpdf.add(table);
//
//            fileCode.delete();
//        }
//        docpdf.close();
//        pdfWriter.close();
//        return pdfName;
//    }
//
//
//}
